package com.sunwayworld.basemodule.rm.train.exampaper.resource.impl;

import com.sunwayworld.basemodule.rm.train.exam.bean.LimsCoreExamBean;
import com.sunwayworld.basemodule.rm.train.exampaper.bean.LimsCoreExamPaperAnswerBean;
import com.sunwayworld.basemodule.rm.train.exampaper.bean.LimsCoreExamPaperAnswerCardDTO;
import com.sunwayworld.basemodule.rm.train.exampaper.bean.LimsCoreExamPaperBean;
import com.sunwayworld.basemodule.rm.train.exampaper.resource.LimsCoreExamPaperResource;
import com.sunwayworld.basemodule.rm.train.exampaper.service.LimsCoreExamPaperAnswerService;
import com.sunwayworld.basemodule.rm.train.exampaper.service.LimsCoreExamPaperService;
import com.sunwayworld.basemodule.rm.train.question.bean.LimsCoreQuestionOptBean;
import com.sunwayworld.framework.data.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.sunwayworld.framework.data.page.Pagination;
import com.sunwayworld.framework.log.annotation.Log;
import com.sunwayworld.framework.log.annotation.LogModule;
import com.sunwayworld.framework.log.annotation.LogType;
import com.sunwayworld.framework.mybatis.mapper.MatchPattern;
import com.sunwayworld.framework.mybatis.mapper.SearchFilter;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.support.activatable.resource.AbstractGenericActivatableResource;
import com.sunwayworld.framework.support.base.resource.AbstractGenericResource;

@LogModule("考卷")
@RestController
@GikamBean
public class LimsCoreExamPaperResourceImpl implements LimsCoreExamPaperResource,
                                                  AbstractGenericResource<LimsCoreExamPaperService, LimsCoreExamPaperBean, Long>,
                                                  AbstractGenericActivatableResource<LimsCoreExamPaperService, LimsCoreExamPaperBean, Long> {

    @Autowired
    private LimsCoreExamPaperService coreExamPaperService;
    
    @Autowired
    private LimsCoreExamPaperAnswerService examPaperAnswerService;

    @Override
    public LimsCoreExamPaperService getService() {
        return coreExamPaperService;
    }

    @Override
    @Log(value = "开始考试", type = LogType.UPDATE)
    public LimsCoreExamPaperBean startExam(RestJsonWrapperBean wrapper) {
        return coreExamPaperService.startExam(wrapper);
    }

    @Override
    @Log(value = "结束考试", type = LogType.UPDATE)
    public void endExam(RestJsonWrapperBean wrapper) {
        coreExamPaperService.endExam(wrapper);
    }

    @Override
    @Log(value = "答题卡查询", type = LogType.SELECT)
    public Pagination<LimsCoreExamPaperAnswerCardDTO> selectExamPaperAnswerCardByExamPaperId(Long id) {
        return examPaperAnswerService.selectExamPaperAnswerCardByExamPaperId(id);
    }

    @Override
    @Log(value = "根据考卷ID和排序号查询考卷答案", type = LogType.SELECT)
    public LimsCoreExamPaperAnswerBean selectExamPaperAnswerByExamPaperIdAndOrderNo(Long id, Integer orderNo) {
        return examPaperAnswerService.selectExamPaperAnswerCardByExamPaperId(id, orderNo);
    }

    @Override
    @Log(value = "根据ID查询考卷答案", type = LogType.SELECT)
    public LimsCoreExamPaperAnswerBean selectExamPaperAnswerById(Long id) {
        return examPaperAnswerService.selectExamPaperAnswerById(id);
    }

    @Override
    @Log(value = "根据考卷答案ID查询试题选项", type = LogType.SELECT)
    public Pagination<LimsCoreQuestionOptBean> selectQuestionOptPaginationByAnswerId(Long answerId, RestJsonWrapperBean wrapper) {
        return examPaperAnswerService.selectQuestionOptPaginationByAnswerId(answerId, wrapper);
    }

    @Override
    @Log(value = "根据考卷ID查询答案", type = LogType.SELECT)
    public Pagination<LimsCoreExamPaperAnswerBean> selectExamPaperAnswerPaginationByExamPaperId(Long id, RestJsonWrapperBean wrapper) {
        return (Pagination<LimsCoreExamPaperAnswerBean>) examPaperAnswerService.selectPaginationByFilter(SearchFilter.instance().match("EXAMPAPERID", id).filter(MatchPattern.EQ), wrapper);
    }

    @Override
    @Log(value = "提交")
    public void submit(RestJsonWrapperBean wrapper) {
        getService().submit(wrapper);
    }

    @Override
    @Log(value = "更新考试人员")
    public void updateExamPaperUser(RestJsonWrapperBean wrapper) {
        getService().updateExamPaperUser(wrapper);
    }

    @Override
    @Log(value = "查询去重的考试编号", type = LogType.SELECT)
    public Page<LimsCoreExamBean> searchExamPaperCode(RestJsonWrapperBean wrapperBean) {
        return getService().searchExamPaperCode(wrapperBean);
    }
}